package com.coolpad.Utils;
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//


import java.net.InetAddress;
import java.net.UnknownHostException;

public class IPv4Utils {
    public IPv4Utils() {
    }

    public static byte[] ipToBytesByInet(String ipAddr) {
        try {
            return InetAddress.getByName(ipAddr).getAddress();
        } catch (Exception var2) {
            throw new IllegalArgumentException(ipAddr + " is invalid IP");
        }
    }

    public static int ipToInt(String ipAddr) {
        try {
            return ByteUtils.readInt(ipToBytesByInet(ipAddr), 0);
        } catch (Exception var2) {
            throw new IllegalArgumentException(ipAddr + " is invalid IP");
        }
    }

    public static int ip2IntInHostOrder(String ip) {
        try {
            byte[] bytes = InetAddress.getByName(ip).getAddress();
            int a = byte2int(bytes[0]);
            int b = byte2int(bytes[1]);
            int c = byte2int(bytes[2]);
            int d = byte2int(bytes[3]);
            int result = d << 24 | c << 16 | b << 8 | a;
            return result;
        } catch (UnknownHostException var7) {
            return 0;
        }
    }

    public static int byte2int(byte b) {
        int l = b & 127;
        if (b < 0) {
            l |= 128;
        }

        return l;
    }
}
